package com.example.shopspring.controller;

import com.example.shopspring.common.ApiConstant;
import com.example.shopspring.common.ResultData;
import com.example.shopspring.entity.ImageClass;
import com.example.shopspring.service.ImageClassService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(ApiConstant.API_VERSION + "/image")
@Slf4j
public class ImageController {

    @Resource
    private ImageClassService imageClassService;

    @GetMapping("/class_list/{current}")
    public ResultData getClassList(@PathVariable Integer current,
                                   @RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
        return imageClassService.getImageClassList(current, size);
    }

    /**
     * 新增或修改图片类
     *
     * @param imageClass
     * @return
     */
    @PostMapping("/save_or_update_class")
    public ResultData saveOrUpdateClass(@RequestBody @Valid ImageClass imageClass) {
        return imageClassService.saveOrUpdateClass(imageClass);
    }
}
